package com.thb.pay.agent.controller;


import com.thb.pay.agent.entity.AgentPassage;
import com.thb.pay.agent.service.AgentPassageService;
import com.thb.pay.api.agent.AgentPassageServiceApi;
import com.thb.pay.api.agent.vo.req.AgentPassageReq;
import com.thb.pay.api.agent.vo.resp.AgentPassageVo;
import com.xiaoleilu.hutool.bean.BeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * <p>
 * 代理商-通道表 前端控制器
 * </p>
 *
 * @author lucky
 * @since 2019-07-21
 */
@Controller
public class AgentPassageController implements AgentPassageServiceApi {

    @Autowired
    private AgentPassageService agentPassageService;

    @Override
    public List<AgentPassageVo> findListByAgentId(@RequestParam("agentId") Long agentId) {
        return agentPassageService.findAllByAgentId(agentId);
    }

    @Override
    public AgentPassageVo getByAgentIdAndProductId(@RequestParam("agentId") Long agentId, @RequestParam("productId") Long productId) {
        return agentPassageService.getByAgentIdAndProductId(agentId, productId);
    }

    @Override
    public void addOrUpdate(@RequestBody AgentPassageReq agentPassageReq) {
        AgentPassage agentPassage = new AgentPassage();
        BeanUtil.copyProperties(agentPassageReq, agentPassage);
        agentPassageService.insertOrUpdate(agentPassage);
    }
}
